package com.gtqing.mall.listener;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.Gson;
import com.gtqing.mall.pojo.PayInfo;
import com.gtqing.mall.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 关于payinfo正确姿势 pay项目提供client.jar,mall项目引入jar包
 * @author gthang
 * @create 2022-05-03-19:46
 */
@Component
@RabbitListener(queues = "payNotify")
@Slf4j
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PayMsgListener {

    @Autowired
    private IOrderService orderService;

    @RabbitHandler
    public void process(String msg){
        log.info("【接收到消息】 => {}",msg);

        PayInfo payInfo = new Gson().fromJson(msg,PayInfo.class);
        log.info("【接收);");
        if (payInfo.getPlatformStatus().equals("SUCCESS")){
//            修改订单里的状态
            orderService.paid(payInfo.getOrderNo());

        };
    }


}
